package com.jeesite.modules.common;

import java.io.File;
import java.io.FileInputStream;
import java.math.BigDecimal;
import java.security.KeyStore;

import javax.net.ssl.SSLContext;

import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
import org.apache.http.ssl.SSLContexts;

/**
 * 加载证书的类
 * @author
 * @since 2017/08/16
 */

@SuppressWarnings("deprecation")
public class CertUtil {


    private static final String mchId = "1504722971";
    private static final String key = "ZRgZoUq5b0MKkO5gDWyc1MNQCdGHu5cK";
    private static String AppID = "wxc86ac9d5537decf6";

    /**
     * 加载证书
     */
    public static SSLConnectionSocketFactory initCert() throws Exception {
        FileInputStream instream = null;
        KeyStore keyStore = KeyStore.getInstance("PKCS12");
        instream = new FileInputStream(new File(""));
        keyStore.load(instream, mchId.toCharArray());

        if (null != instream) {
            instream.close();
        }

        SSLContext sslcontext = SSLContexts.custom().loadKeyMaterial(keyStore,mchId.toCharArray()).build();
        SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(sslcontext, new String[]{"TLSv1"}, null, SSLConnectionSocketFactory.BROWSER_COMPATIBLE_HOSTNAME_VERIFIER);

        return sslsf;
    }

    public static void main(String[] args) {
        System.out.println(new BigDecimal("0.1").toString());
    }
}

